package com.wsb.wetchat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author wang shaobo
 * @date 2022/6/29  15:44
 */
@Configuration
@EnableAsync
public class ThreadPoolConfig {

    @Bean
    public Executor asyncExector(){


        ThreadPoolTaskExecutor poolExecutor = new ThreadPoolTaskExecutor();
        poolExecutor.setCorePoolSize(2);
        poolExecutor.setMaxPoolSize(3);
        poolExecutor.setKeepAliveSeconds(10);
        poolExecutor.setQueueCapacity(4);
        poolExecutor.setThreadNamePrefix("线程池-线程-");

        poolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());

        poolExecutor.initialize();

        return poolExecutor;




    }


}
